<?php
// include function files for this application
require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php');
// start session which may be needed later
// start it now because it must go before headers
if (!session_id()) { session_start(); }


//create short variable names
$username = $_POST['username'];
$password = $_POST['password'];

if ($username && $password) {
	// they have just tried logging in
	$login_result = login($username, $password);
	}

if (($login_result == 'no_username' || $login_result == 'wrong_password') && $login_result != '1') {
	// unsuccessful login
	do_html_header('Problem:', staysmall, $uny);
	echo '<span class="redtext">You could not be logged in.</span><br />
		Wrong username and/or password please try again or use the forgot password link at the bottom of the page.';
	display_login_form();
	print_brs(6);
	do_html_footer(news);
	exit;
	}

if (check_valid_user() && $_SESSION['admin'] == 't') {
	// We will redirect them to the admin_home page because they are already logged in.
	if ($_SESSION['last_login'] < (time() - 15724800)) {
		header("Location: ".$conf['base_path']."registration/contact_info_confirm.php");
		} else {
		header("Location: ".$conf['base_path']."registration/admin_home.php"); 
		}
	exit;
	}

if (check_valid_user()) {
	// We will redirect them to the attendee_home page because they are already logged in.
	if ($_SESSION['last_login'] < (time() - 15724800)) {
		header("Location: ".$conf['base_path']."registration/contact_info_confirm.php");
		} else {
		header("Location: ".$conf['base_path']."registration/attendee_home.php"); 
		}
	exit;
	}

else {
	do_html_header('Login to UNY-Con event registration system', staysmall, $uny);
	display_login_form();
	//do_html_header('Down for Maintenance', staysmall);
	//echo "The on-line system is currently down for maintenance<br />\n";
	print_brs(6);
	do_html_footer(news);
	}
?>